#region File Description
//-----------------------------------------------------------------------------
// SpriteFontControl.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion

#region Using System to need Animation
using System.Diagnostics;
using System.Windows.Forms;
#endregion

#region Aim Engine Using

using System;
using System.Collections;
using System.Collections.Generic;

using Microsoft.Xna.Framework.Input;

using AimGameEngine.NodeTemples;
using AimGameEngine.NodeEditorObject;
using AimGameEngine.EditorObject;

using AimGameLibrary;
using AimGameLibrary.GameObject;
using AimGameLibrary.ScreenManager;

#endregion


namespace AimGameEngine.Compornet
{
    using GdiColor = System.Drawing.Color;
    using XnaColor = Microsoft.Xna.Framework.Color;
    using GdiPoint = System.Drawing.Point;
    using XnaPoint = Microsoft.Xna.Framework.Point;
    using XnaKey = Microsoft.Xna.Framework.Input.Keys;

    public enum StateNode
    {
        Select,
        NoneSelect
    }

    public enum ObjectType
    { 
        Node,
        Connecter,
        Line
    }

    enum ImageStore
    {
        ImageNodeBody,
        ImageNodePoint,
        ImageNodeInput,
        ImageNodeOutput,
        ImageGroupTitle,
        ImageGroupBody,
        ImageGroupControl
    }

    /// <summary>
    /// Example control inherits from GraphicsDeviceControl, which allows it to
    /// render using a GraphicsDevice. This control shows how to use ContentManager
    /// inside a WinForms application. It loads a SpriteFont object through the
    /// ContentManager, then uses a SpriteBatch to draw text. The control is not
    /// animated, so it only redraws itself in response to WinForms paint messages.
    /// </summary>
    class SpriteNodeControl : GraphicsDeviceControl
    {
        ContentManager content;
        SpriteBatch spriteBatch;

        SpriteBatch GetSpriteBatch { get { return spriteBatch; } }

        SpriteFont font;

        Stopwatch timer;
        float Test = 0;

        public Dictionary<String, Texture2D> StoreTexture2D;
        /// <summary>
        /// Don't Use
        /// </summary>
        List<IDraw> ListDraw;
        List<IUpdateMainTime> ListUpdateTime;
        /// <summary>
        /// Use Node to that list
        /// </summary>
        public DictionaryType MainDictionaryType;

        /// <summary>
        /// List is callback
        /// </summary>
        Dictionary<String, LinkLine> DictionaryLinkLine;
        Dictionary<String, NodeGroup> DictionaryNodeGroup;

        public BackupActionsControl backupaction;

        public Camera camera;
        Grid grid;

        Vector2 DropPosition;
        public Vector2 DropPositioN { get { return DropPosition; } set { DropPosition = value; } }

        #region InputState
        public InputState inputstate;
        #endregion

        /// <summary>
        /// Debug
        /// </summary>

        public Vector2 GroupPosition;
        public Vector2 GetGroupPositioN { get { return GroupPosition; } set { GroupPosition = value; } }
        public RectangleSelect rectangleselect;

        String message;
        public String Massage3;
        public String Massage2;

        public Boolean Start = false;

        /// <summary>
        /// Initializes the control, creating the ContentManager
        /// and using it to load a SpriteFont.
        /// </summary>
        protected override void Initialize()
        {
            content = new ContentManager(Services, "Content");

            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = content.Load<SpriteFont>("Arial");

            #region Time for animation
            // Start the animation timer.
            timer = Stopwatch.StartNew();

            // Hook the idle event to constantly redraw our animation.
            Application.Idle += delegate { Invalidate(); };
            #endregion

            backupaction = new BackupActionsControl();

            StoreTexture2D = new Dictionary<string, Texture2D>();
            StoreTexture2D.Add(ImageStore.ImageNodeBody.ToString(), content.Load<Texture2D>("Node/NodeBody"));
            //StoreTexture2D.Add("NodeFrame", content.Load<Texture2D>("Node/NodeFrame"));
            StoreTexture2D.Add(ImageStore.ImageNodePoint.ToString(), content.Load<Texture2D>("Node/pixel"));
            StoreTexture2D.Add(ImageStore.ImageNodeInput.ToString(), content.Load<Texture2D>("Node/CIn"));
            StoreTexture2D.Add(ImageStore.ImageNodeOutput.ToString(), content.Load<Texture2D>("Node/COut"));

            StoreTexture2D.Add(ImageStore.ImageGroupTitle.ToString(), content.Load<Texture2D>("GroupNode/TitleGroup"));
            StoreTexture2D.Add(ImageStore.ImageGroupBody.ToString(), content.Load<Texture2D>("GroupNode/BodyGroup"));
            StoreTexture2D.Add(ImageStore.ImageGroupControl.ToString(), content.Load<Texture2D>("GroupNode/ControlGroup"));

            camera = new Camera("Nodecamera");

            grid = new Grid(spriteBatch, camera ,StoreTexture2D[ImageStore.ImageNodePoint.ToString()]);

            ListDraw = new List<IDraw>();
            ListUpdateTime = new List<IUpdateMainTime>();

            MainDictionaryType = new DictionaryType();

            DictionaryLinkLine = new Dictionary<string, LinkLine>();
            DictionaryNodeGroup = new Dictionary<string, NodeGroup>();

            inputstate = new InputState();


            rectangleselect = new RectangleSelect(spriteBatch, camera);
            rectangleselect.SetupSourceAndTexture(StoreTexture2D[ImageStore.ImageNodePoint.ToString()]);
            this.ListDraw.Add(rectangleselect);
        }
        
        public void CreateNewProject(NodeList data)
        {
            Start = false;
            
            NewNode(data.ListNode[NodeTypeValue.Screen.ToString()], new System.Drawing.Point(340 + ScreenPosition.X, 50 + ScreenPosition.Y), null);
            NewNode(data.ListNode[NodeTypeValue.Draw.ToString()], new System.Drawing.Point(170 + ScreenPosition.X, 130 + ScreenPosition.Y), null);
            NewNode(data.ListNode[NodeTypeValue.Update.ToString()], new System.Drawing.Point(520 + ScreenPosition.X, 130 + ScreenPosition.Y), null);

            FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Screen.ToString()]["Screen0"].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Draw.ToString()]["Draw0"].ListConnectpointOutput[0]);
            FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Screen.ToString()]["Screen0"].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()]["Update0"].ListConnectpointOutput[0]);

            Start = true;
        }

        /// <summary>
        /// Disposes the control, unloading the ContentManager.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                content.Unload();
            }

            base.Dispose(disposing);
        }

        /// <summary>
        /// Draws the control, using SpriteBatch and SpriteFont.
        /// </summary>
        protected override void Draw()
        {

            #region Update Time
            // Spin the triangle according to how much time has passed.
            float time = (float)timer.Elapsed.TotalSeconds;
            Test += time;
            #endregion

            /// Update InputState
            inputstate.Update();

            grid.myArea = this.ClientRectangle;
            grid.UpdateTime(timer.Elapsed);

            MainUpdate();

            List<IUpdateMainTime> tempupdatetime = new List<IUpdateMainTime>();
            foreach (IUpdateMainTime objupdatetime in ListUpdateTime)
                tempupdatetime.Add(objupdatetime);
            foreach (IUpdateMainTime temptime in tempupdatetime)
                temptime.UpdateTime(timer.Elapsed);


            GraphicsDevice.Clear(Color.CornflowerBlue);
            // 0 = Front , 1 = Back
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied);

            // Debug Draw
            spriteBatch.DrawString(font, message, new Vector2(23, 23), Color.White,0,Vector2.Zero,1,SpriteEffects.None,0.00001f);

            #region Node Draw
            List<IDraw> TempDraw = new List<IDraw>();
            foreach (IDraw NodeDraw in ListDraw)
                TempDraw.Add(NodeDraw);
            foreach (IDraw NodeDraw in TempDraw)
                NodeDraw.Draw();
            #endregion

            grid.Draw();
            //if (rectangleselect.VisiblE)
            //{ 
                
            //}

            spriteBatch.End();

        }

        public System.Drawing.Point ScreenPosition { get { return this.PointToScreen(new System.Drawing.Point(this.Location.X, this.Location.Y)); } }

        void MainUpdate()
        {
            HandleInput();
            
            //Massage2 = this.ClientRectangle.ToString();
            //Massage3 = LinkSelect +" | "+ DictionaryLinkLine.Count;

            message = "" + Massage2 + Massage3;
        }

        void HandleInput()
        {
            PlayerIndex playerIndex;
            //if (MainController.Pressed(Microsoft.Xna.Framework.Input.Keys.Delete))
            #region Delete
            if (inputstate.IsNewKeyPress(XnaKey.Delete, null, out playerIndex))
            {
                String mm = "";
                if (NodeSelect != null)
                {
                    mm = NodeSelect.MyData.MyName;

                    DeleteNode();

                    Massage2 = "Delete" + mm;
                    
                }
                DeleteLinkline();
                
                Reset();
            }
            #endregion

            if (inputstate.IsNewKeyPress(XnaKey.F2, null, out playerIndex))
            {
                if (NodeSelect != null)
                    NodeSelect.Rename();
            }
            //if (inputstate.IsNewKeyPress(XnaKey.PageUp, null, out playerIndex))
            //{
            //    foreach (String keys in MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct].Keys)
            //        MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][keys].VisiblE = !MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][keys].VisiblE;
            //}
        }

        public void DeleteNode()
        {
            if (!backupaction.Doing)
            {
                backupaction.TempSave(NodeSelect, BackupMode.DeleteNode);
                backupaction.BackupMove(BackupMode.DeleteNode);
            }

            NodeSelect.Remove();
            NodeSelect = null;
        }
        void DeleteLinkline()
        {
            if (LinkLineSelect != null)
            {
                if (LinkLineSelect.StartConnecter.MySyco == Syco.Input)
                    LinkLineSelect.StartConnecter.MyNode.ClearInput(LinkLineSelect.StartConnecter, LinkLineSelect.EndConnecter, LinkLineSelect.EndConnecter.MyNode.MyData.MyName);
                else if (LinkLineSelect.EndConnecter.MySyco == Syco.Input)
                    LinkLineSelect.EndConnecter.MyNode.ClearInput(LinkLineSelect.EndConnecter, LinkLineSelect.StartConnecter, LinkLineSelect.StartConnecter.MyNode.MyData.MyName);
                
                if (!backupaction.Doing)
                {
                    backupaction.TempSave(LinkLineSelect, BackupMode.DeleteLink);
                    backupaction.BackupMove(BackupMode.DeleteLink);
                }

                LinkLineSelect.Isconnect = false;

                //Massage2 = "Delete" + mm;
                LinkLineSelect = null;
            }
        }

        #region System Return

        Color ReturnColorState(StateNode statenode,ObjectType objecttype)
        {
            if (objecttype == ObjectType.Node && statenode == StateNode.NoneSelect)
                return EditorColor.Default.Node_NoneSelect;
            else if (objecttype == ObjectType.Node && statenode == StateNode.Select)
                return EditorColor.Default.Node_Select;
            else if (objecttype == ObjectType.Connecter && statenode == StateNode.NoneSelect)
                return EditorColor.Default.Connecter_NoneSelect;
            else if (objecttype == ObjectType.Connecter && statenode == StateNode.Select)
                return EditorColor.Default.Connecter_Select;
            else if (objecttype == ObjectType.Line && statenode == StateNode.NoneSelect)
                return EditorColor.Default.Line_NoneSelect;
            else if (objecttype == ObjectType.Line && statenode == StateNode.Select)
                return EditorColor.Default.Line_Select;
            else return Color.White;
        }
       
        String ReturnCalculadKeys(ObjectType Type,String LastKeys)
        {
            if (LastKeys != "")
            {
                int Length = Type.ToString().Length;
                int Index = Convert.ToInt32(LastKeys.Substring(Length));
                return Type.ToString() + (Index + 1);
            }
            else return Type.ToString() + 0;
        }
        String ReturnCalculadKeys(NodeTypeValue Type, String LastKeys)
        {
            if (LastKeys != "")
            {
                int Length = Type.ToString().Length;
                int Index = Convert.ToInt32(LastKeys.Substring(Length));
                int i = 1;
                while (MainDictionaryType.GetMaindictionarY[Type.ToString()].ContainsKey(Type.ToString() + (Index + i)))
                    i++;
                
                return Type.ToString() + (Index + i);
            }
            else return Type.ToString() + 0;
        }
        String ReturnCalculadKeys(String Type, String LastKeys, Dictionary<String, LinkLine> dic)
        {
            if (LastKeys != "")
            {
                int Length = Type.Length;
                int Index = Convert.ToInt32(LastKeys.Substring(Length));
                int i = 1;
                while (dic.ContainsKey(Type + (Index + i)))
                    i++;

                return Type + (Index + i);
            }
            else return Type + 0;
        }
        String ReturnCalculadKeys(String Type, String LastKeys, Dictionary<String, NodeGroup> dic)
        {
            if (LastKeys != "")
            {
                int Length = Type.Length;
                int Index = Convert.ToInt32(LastKeys.Substring(Length));
                int i = 1;
                while (dic.ContainsKey(Type + (Index + i)))
                    i++;

                return Type + (Index + i);
            }
            else return Type + 0;
        }
        
        bool ReturnCollisionClick(Rectangle Object, MouseEventArgs Mouse)
        {
            if (Object.Intersects(new Rectangle(Mouse.X,Mouse.Y, 1, 1)))
                return true;
            else return false;
        }

        bool Connectting(Connecter connecter_1, Connecter connecter_2)
        {
            if (connecter_1.MyNode.GetType() != typeof(NodeScreen) && connecter_2.MyNode.GetType() != typeof(NodeScreen))
            {
                if ((connecter_1.MyType == NodeTypeValue.Group_Value || connecter_2.MyType == NodeTypeValue.Group_Value ))
                {
                    if (CheckGroupNumder(connecter_1.MyNode) && CheckGroupNumder(connecter_2.MyNode))
                    {
                        if ((connecter_1.MySyco != connecter_2.MySyco))
                            return true;
                        else return false;
                    }
                    else if (CheckGroupCondition(connecter_1.MyType) || CheckGroupCondition(connecter_2.MyType))
                    {
                        if ((connecter_1.MySyco != connecter_2.MySyco))
                            return true;
                        else return false;
                    }else if (connecter_1.MyType == NodeTypeValue.SpriteEffects && connecter_2.MyNode.GetType() == typeof(NodeEqualsValue))
                    {
                        if (connecter_1.MySyco != connecter_2.MySyco)
                            return true;
                        else return false;
                    }
                    else if (connecter_1.MyNode.GetType() == typeof(NodeEqualsValue) && connecter_2.MyType == NodeTypeValue.SpriteEffects)
                    {
                        if (connecter_1.MySyco != connecter_2.MySyco)
                            return true;
                        else return false;
                    }else  return false;
                }else
                {
                    if ((connecter_1.MySyco != connecter_2.MySyco) && (connecter_1.MyType == connecter_2.MyType))
                        return true;
                    else return false;
                }
            }
            else
            {
                 if ((connecter_1.MyNode.GetType() == typeof(NodeDraw) || connecter_1.MyNode.GetType() == typeof(NodeUpdate) || connecter_1.MyNode.GetType() == typeof(NodeCamera) || connecter_1.MyNode.GetType() == typeof(NodeScreen)) &&
                (connecter_2.MyNode.GetType() == typeof(NodeDraw) || connecter_2.MyNode.GetType() == typeof(NodeUpdate) || connecter_2.MyNode.GetType() == typeof(NodeCamera) || connecter_2.MyNode.GetType() == typeof(NodeScreen)))
                {
                    if ((connecter_1.MySyco != connecter_2.MySyco) && (connecter_1.MyType == connecter_2.MyType))
                        return true;
                    else return false;
                }
                else return false;
            }
        }
        
        bool CheckGroupNumder(NodeObject inputObject)
        {
            if (inputObject.GetType() == typeof(NodeInt) || inputObject.GetType() == typeof(NodeFloat))
                return true;
            else return false;
        }

        bool CheckGroupCondition(NodeTypeValue inputType)
        {
            if (inputType == NodeTypeValue.Boolean || inputType == NodeTypeValue.Int || inputType == NodeTypeValue.Float ||
                inputType == NodeTypeValue.KeyController || inputType == NodeTypeValue.ButtonController)
                return true;
            else return false;
        }

        public NodeObject ReturnCollisionNodeObject(MouseEventArgs e)
        {
            foreach (String Key in MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct].Keys)
            {
                NodeObject Node = MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][Key];
                if (ReturnCollisionClick(Node.NodeBody, e))
                {
                    return Node;
                    //break;
                }
            }
            return null;
        }

        public Connecter ReturnConllisionConnecter(MouseEventArgs e)
        {
            foreach (String Key in MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct].Keys)
            {
                NodeObject Node = MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][Key];
                foreach (Connecter connect in Node.ListConnectpoint)
                {
                    if (ReturnCollisionClick(connect.NodeBody, e))
                        return connect;
                }
                //return null;
            }
            return null;
        }

        public Connecter ReturnConllisionConnecter(NodeObject node, MouseEventArgs e)
        {
            foreach (Connecter connect in node.ListConnectpoint)
            {
                if (ReturnCollisionClick(connect.NodeBody, e))
                    return connect;
            }
            return null;
        }

        public bool CheckClickNode(object sender, MouseEventArgs e)
        {
            foreach (String Key in MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct].Keys)
            {
                NodeObject Node = MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][Key];
                if (Node.NodeBody.Intersects(new Rectangle(e.X, e.Y, 1, 1)))
                {
                    NodeSelect = Node;
                    return true;
                }
            }
            return false;
        }
        
        #endregion

        /// <summary>
        /// Update to New Node
        /// </summary>
        public String NewNode(NodeData inputNode, System.Drawing.Point inputPosition,String InputSaveName)
        {
            System.Drawing.Point positionThisScreen = this.PointToScreen(new System.Drawing.Point(this.Location.X, this.Location.Y));
            Vector2 NodePosition = new Vector2(inputPosition.X-positionThisScreen.X,inputPosition.Y-positionThisScreen.Y);
            
            NodeData NewData = inputNode.Copy();
            NodeObject temp;
            String FindLastKey = "";
            
            foreach (String K in MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()].Keys)
                FindLastKey = K;


            NewData.MyName = ReturnCalculadKeys(inputNode.MyType, FindLastKey);
            //NewData.MyName = ReturnCalculadKeys(inputNode.MyType.ToString(), FindLastKey, MainDictionaryType.ConvertToGameBaseObject(inputNode.MyType.ToString()));
            switch (NewData.MyType)
            { 
                case NodeTypeValue.Screen:          temp = new NodeScreen           (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.ScreenControl:   temp = new NodeScreenControl    (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Draw:            temp = new NodeDraw             (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Update:          temp = new NodeUpdate           (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Camera:          temp = new NodeCamera           (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.TackCamera:      temp = new NodeTackCamera       (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Boolean :        temp = new NodeBoolean          (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Int :            temp = new NodeInt              (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Float:           temp = new NodeFloat            (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Vector2:         temp = new NodeVector2          (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Rectangle:       temp = new NodeRectangle        (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                //case NodeTypeValue.String:
                //    break;
                case NodeTypeValue.Color:           temp = new NodeColor            (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.SpriteEffects:   temp = new NodeSpriteEffects    (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]);break;
                case NodeTypeValue.Texture2D:       temp = new NodeTexture2D        (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                //case NodeTypeValue.SpriteFont:
                //    break;
                case NodeTypeValue.DrawSprite:      temp = new NodeDrawSprite       (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                //case NodeTypeValue.DrawString:
                //    break;
                case NodeTypeValue.Animation2D:     temp = new NodeAnimation2D      (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Body:            temp = new NodeBody             (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Gravity:         temp = new NodeGravity          (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.Collision:       temp = new NodeCollision        (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.IrrklangPlayer:  temp = new NodeIrrKlangPlayer   (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.VideoPlayer:     temp = new NodeVideoPlayer      (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.KeyController:   temp = new NodeKeyController    (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.ButtonController:temp = new NodeButtonController (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]);break;
                case NodeTypeValue.AddValue:        temp = new NodeAddValue         (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]);break;
                case NodeTypeValue.SubtracValue:    temp = new NodeSubtractValue    (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]);break;
                case NodeTypeValue.MultiplyValue:   temp = new NodeMultiplyValue    (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.DivisionValue:   temp = new NodeDivisionValue    (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.RemainderValue:  temp = new NodeRemainderValue   (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.EqualsValue:     temp = new NodeEqualsValue      (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                case NodeTypeValue.IfElse:          temp = new NodeIfelse           (this.spriteBatch, this.camera, NewData, this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], MainDictionaryType.GetMaindictionarY[inputNode.MyType.ToString()]); break;
                default :
                    temp = new NodeObject(this.spriteBatch, this.camera
                        , new NodeData("", inputNode.MyLevel, inputNode.MyIndex, inputNode.MyType)
                        , this.ListDraw, this.ListUpdateTime, MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct], null);
                    break;
            }

            temp.Setup(StoreTexture2D[ImageStore.ImageNodeBody.ToString()]
                , StoreTexture2D[ImageStore.ImageNodeInput.ToString()]
                , StoreTexture2D[ImageStore.ImageNodeOutput.ToString()], this.font);
            temp.MyViewData.Position = NodePosition - camera.MyViewData.Position;
            
            if (InputSaveName != null)
                temp.MyData.MyName = InputSaveName;

            temp.AddMetoList();

            if (!backupaction.Doing && Start)
            {
                backupaction.TempSave(temp, BackupMode.CreateNode);
                backupaction.BackupMove(BackupMode.CreateNode);
            }

            return temp.MyData.MyName;
        }

        public void NewTemple(NodeList data,NodeTemple inputNode, System.Drawing.Point inputPosition, String InputSaveName)
        {
            List<string> ListNodeName = new List<string>();
            if (inputNode.MyType == NodeTypeTemple.Charater)
            {
                #region Charater

                #region Create
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Draw.ToString()], inputPosition, null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Update.ToString()], new GdiPoint(inputPosition.X + 500, inputPosition.Y + 0), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.DrawSprite.ToString()], new GdiPoint(inputPosition.X + 0, inputPosition.Y + 100), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Texture2D.ToString()], new GdiPoint(inputPosition.X - 100, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Body.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 200), null));
                    ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 300), null));
                    ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 400), null));
                    ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 500), null));
                    ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 600), null));
                    ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 700), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Animation2D.ToString()], new GdiPoint(inputPosition.X + 300, inputPosition.Y + 200), null));
                    ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Int.ToString()], new GdiPoint(inputPosition.X + 300, inputPosition.Y + 300), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Gravity.ToString()], new GdiPoint(inputPosition.X + 500, inputPosition.Y + 100), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Collision.ToString()], new GdiPoint(inputPosition.X + 500, inputPosition.Y + 200), null));
                #endregion

                #region PreSetup
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].InputMode = NodeInputMode.Float_5;
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].SetupProprety();
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].InputMode = NodeInputMode.Int_1;
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].SetupProprety();
                ((NodeGravity)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Gravity.ToString()][ListNodeName[12]]).Strength = 1;
                #endregion

                #region Draw
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Draw.ToString()][ListNodeName[0]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointOutput[0]);
                #endregion

                #region Update
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()][ListNodeName[1]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].ListConnectpointOutput[1]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()][ListNodeName[1]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Gravity.ToString()][ListNodeName[12]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()][ListNodeName[1]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Collision.ToString()][ListNodeName[13]].ListConnectpointOutput[1]);
                #endregion

                #region DrawSprite
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Texture2D.ToString()][ListNodeName[3]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[2]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].ListConnectpointOutput[0]);
                #endregion

                #region Body
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[5]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[6]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[2]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[7]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[3]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[8]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[4]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[9]].ListConnectpointOutput[0]);
                #endregion

                #region Animation2D
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Texture2D.ToString()][ListNodeName[3]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Int.ToString()][ListNodeName[11]].ListConnectpointOutput[0]);
                #endregion

                #region Gravity
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Gravity.ToString()][ListNodeName[12]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[1]);
                #endregion

                #region Collision
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Collision.ToString()][ListNodeName[13]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[1]);
                #endregion

                #endregion
            }
            else if (inputNode.MyType == NodeTypeTemple.GameObject)
            {
                #region GameObject

                #region Create
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Draw.ToString()], inputPosition, null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Update.ToString()], new GdiPoint(inputPosition.X + 200, inputPosition.Y), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.DrawSprite.ToString()], new GdiPoint(inputPosition.X + 0, inputPosition.Y + 100), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Texture2D.ToString()], new GdiPoint(inputPosition.X - 100, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Body.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Rectangle.ToString()], new GdiPoint(inputPosition.X + 300, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Collision.ToString()], new GdiPoint(inputPosition.X + 200, inputPosition.Y + 100), null));
                #endregion

                #region Draw
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Draw.ToString()][ListNodeName[0]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointOutput[0]);
                #endregion

                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()][ListNodeName[1]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Collision.ToString()][ListNodeName[6]].ListConnectpointOutput[1]);

                #region DrawSprite
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Texture2D.ToString()][ListNodeName[3]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[2]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Rectangle.ToString()][ListNodeName[5]].ListConnectpointOutput[0]);
                #endregion

                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Collision.ToString()][ListNodeName[6]].ListConnectpointInput[1]
               , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[1]);

                #endregion
            }
            else if (inputNode.MyType == NodeTypeTemple.CharaterWithTempleImage)
            {
                #region CharaterWithTempleImage

                #region Create
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Draw.ToString()], inputPosition, null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Update.ToString()], new GdiPoint(inputPosition.X + 500, inputPosition.Y + 0), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.DrawSprite.ToString()], new GdiPoint(inputPosition.X + 0, inputPosition.Y + 100), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Texture2D.ToString()], new GdiPoint(inputPosition.X - 100, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Body.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 300), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 400), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 500), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 600), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Float.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 700), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Animation2D.ToString()], new GdiPoint(inputPosition.X + 300, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Int.ToString()], new GdiPoint(inputPosition.X + 300, inputPosition.Y + 300), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Gravity.ToString()], new GdiPoint(inputPosition.X + 500, inputPosition.Y + 100), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Collision.ToString()], new GdiPoint(inputPosition.X + 500, inputPosition.Y + 200), null));
                #endregion

                #region PreSetup
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Texture2D.ToString()][ListNodeName[3]].MyData.Data = "TempleResources\\basicMario.png";
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].InputMode = NodeInputMode.Float_5;
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].SetupProprety();
                ((NodeFloat)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[7]]).myfloat = 51f;
                ((NodeFloat)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[8]]).myfloat = 48f;
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].InputMode = NodeInputMode.Int_1;
                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].SetupProprety();
                ((NodeAnimation2D)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]]).MyFrameData = new FrameData(153, 144, 3, 3, 3);
                #region Setup KeyFrame
                List<List<int>> key = new List<List<int>>();
                List<int> idal = new List<int>();
                idal.Add(0);
                key.Add(idal);
                List<int> walk = new List<int>();
                walk.Add(0);
                walk.Add(1);
                walk.Add(2);
                key.Add(walk);
                List<int> jump = new List<int>();
                jump.Add(0);
                key.Add(jump);
                List<string> acion = new List<string>();
                acion.Add("Idal");
                acion.Add("Walk");
                acion.Add("Jump");
                List<bool> playloop = new List<bool>();
                playloop.Add(false);
                playloop.Add(true);
                playloop.Add(false);
                #endregion
                ((NodeAnimation2D)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]]).MyKeyFrameData = new KeyFrameData(key, acion, playloop);
                ((NodeGravity)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Gravity.ToString()][ListNodeName[12]]).Strength = 1;
                #endregion

                #region Draw
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Draw.ToString()][ListNodeName[0]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointOutput[0]);
                #endregion

                #region Update
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()][ListNodeName[1]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].ListConnectpointOutput[1]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()][ListNodeName[1]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Gravity.ToString()][ListNodeName[12]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()][ListNodeName[1]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Collision.ToString()][ListNodeName[13]].ListConnectpointOutput[1]);
                #endregion

                #region DrawSprite
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Texture2D.ToString()][ListNodeName[3]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[2]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].ListConnectpointOutput[0]);
                #endregion

                #region Body
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[5]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[6]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[2]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[7]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[3]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[8]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointInput[4]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Float.ToString()][ListNodeName[9]].ListConnectpointOutput[0]);
                #endregion

                #region Animation2D
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Texture2D.ToString()][ListNodeName[3]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Animation2D.ToString()][ListNodeName[10]].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Int.ToString()][ListNodeName[11]].ListConnectpointOutput[0]);
                #endregion

                #region Gravity
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Gravity.ToString()][ListNodeName[12]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[1]);
                #endregion

                #region Collision
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Collision.ToString()][ListNodeName[13]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[1]);
                #endregion

                #endregion
            }
            else if (inputNode.MyType == NodeTypeTemple.GameObjectWithTempleImage)
            {
                #region GameObjectWithTempleImage

                #region Create
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Draw.ToString()], inputPosition, null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Update.ToString()], new GdiPoint(inputPosition.X + 200, inputPosition.Y), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.DrawSprite.ToString()], new GdiPoint(inputPosition.X + 0, inputPosition.Y + 100), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Texture2D.ToString()], new GdiPoint(inputPosition.X - 100, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Body.ToString()], new GdiPoint(inputPosition.X + 100, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Rectangle.ToString()], new GdiPoint(inputPosition.X + 300, inputPosition.Y + 200), null));
                ListNodeName.Add(NewNode(data.ListNode[NodeTypeValue.Collision.ToString()], new GdiPoint(inputPosition.X + 200, inputPosition.Y + 100), null));
                #endregion

                MainDictionaryType.GetMaindictionarY[NodeTypeValue.Texture2D.ToString()][ListNodeName[3]].MyData.Data = "TempleResources\\box.png";
                ((NodeRectangle)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Rectangle.ToString()][ListNodeName[5]]).myrectangle = new Rectangle(0,0,100,100);
                ((NodeBody)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]]).myvector2 = new Vector2(0, 300);
                ((NodeBody)MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]]).mysize = new Vector2(100,100);

                #region Draw
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Draw.ToString()][ListNodeName[0]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointOutput[0]);
                #endregion

                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Update.ToString()][ListNodeName[1]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Collision.ToString()][ListNodeName[6]].ListConnectpointOutput[1]);

                #region DrawSprite
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[0]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Texture2D.ToString()][ListNodeName[3]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[1]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[0]);
                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.DrawSprite.ToString()][ListNodeName[2]].ListConnectpointInput[2]
                , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Rectangle.ToString()][ListNodeName[5]].ListConnectpointOutput[0]);
                #endregion

                FirstConnect(MainDictionaryType.GetMaindictionarY[NodeTypeValue.Collision.ToString()][ListNodeName[6]].ListConnectpointInput[1]
               , MainDictionaryType.GetMaindictionarY[NodeTypeValue.Body.ToString()][ListNodeName[4]].ListConnectpointOutput[1]);

                #endregion
            }  
        }

        public void CreateGroup()
        {
            NewGroup(rectangleselect.NodeSelect,StateGroup.Maximize);
            rectangleselect.Clean(ReturnColorState(StateNode.NoneSelect, ObjectType.Node));
        }
        public void NewGroup(List<NodeObject> list,StateGroup state)
        {
            String FindLastKey = "";

            foreach (String K in DictionaryNodeGroup.Keys)
                FindLastKey = K;

            NodeGroup nodegroup = new NodeGroup(this.spriteBatch, this.camera, this.ListDraw, DictionaryNodeGroup);
            nodegroup.LoadTexture(StoreTexture2D[ImageStore.ImageGroupTitle.ToString()], StoreTexture2D[ImageStore.ImageGroupBody.ToString()], StoreTexture2D[ImageStore.ImageGroupControl.ToString()]);
            nodegroup.Setup(list);
            nodegroup.MyViewData.Name = ReturnCalculadKeys(NodeGroup.Group, FindLastKey, DictionaryNodeGroup);
            nodegroup.AddMetoList();

            if (state == StateGroup.Minimize)
                nodegroup.SetupState();
            
        }

        #region Save and Load

        public void CreateLodaData(Identification getdata , NodeList MyNodeList)
        {
            int countIndexNodeData = 0;
            String tempName;
            String NowCreate;
            Point tempPosition;

            if (getdata != null)
            { 
                foreach (object obj in getdata.Items)
                {
                    if (obj.GetType() == typeof(NodeData))
                    {
                        NodeData node = (NodeData)obj;
                        tempName = (String)getdata.Items.GetValue(countIndexNodeData + 1);
                        tempPosition = (Point)getdata.Items.GetValue(countIndexNodeData + 2);
                        //tempPosition = (Point)getdata.Items.GetValue(countIndexNodeData + 1);
                        NowCreate = NewNode(MyNodeList.ListNode[node.MyType.ToString()], new System.Drawing.Point(tempPosition.X + ScreenPosition.X, tempPosition.Y + ScreenPosition.Y),node.MyName);
                        MainDictionaryType.GetMaindictionarY[node.MyType.ToString()][NowCreate].MyViewData.Name = tempName;
                    }
                    countIndexNodeData++;
                }
            }
        }

        public void SetupAfterLoadData(Identification getdata)
        {
            int countIndexNodeData = 0;
             if (getdata != null)
            {
                foreach (object obj in getdata.Items)
                {
                    if (obj.GetType() == typeof(NodeData))
                    {
                        NodeData node = (NodeData)obj;
                        MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][node.MyName].LoadData(getdata, countIndexNodeData + 2);
                    }
                    countIndexNodeData++;
                }
             }
        }

        public void ClearALL()
        {
            Start = false;

            NodeSelect = null;
            NodeGroupSelect = null;
            LinkLineSelect = null;

            Reset();

            ListDraw.Clear();
            ListUpdateTime.Clear();

            MainDictionaryType.ClearAll();

            DictionaryLinkLine.Clear();
            DictionaryNodeGroup.Clear();

            backupaction.ClearAll();

            //
            ListDraw.Add(rectangleselect);
        }

        public void SaveGroup(ArrayList list)
        {
            foreach (String Groupkey in DictionaryNodeGroup.Keys)
                DictionaryNodeGroup[Groupkey].Save(list);
        }

        public void UnminimizeGroup()
        {
            foreach (String Groupkey in DictionaryNodeGroup.Keys)
                if (DictionaryNodeGroup[Groupkey].MyStatE == StateGroup.Minimize)
                    DictionaryNodeGroup[Groupkey].SetupState();

            // UpdatePosition
            this.Draw();
        }

        public void MinimizeGroup()
        { 
            foreach (String Groupkey in DictionaryNodeGroup.Keys)
                DictionaryNodeGroup[Groupkey].SetupState();

            this.Draw();
        }

        #endregion

        #region Parametor

        Vector2 SlastPosition;
        Vector2 NodeLastPosition;
        Vector2 NewMove;

        NodeObject NodeSelect;
        //ArrayList PackData;
        public NodeObject NodeselecT { get { return NodeSelect; } }
        Connecter ConnecterSelect;
        LinkLine LinkLineSelect;
        NodeGroup NodeGroupSelect;
        String LinkSelect;
        bool HoleClick;
        
        #endregion

        void FirstConnect(Connecter Connecter1, Connecter Connecter2)
        {
            System.TimeSpan time = new TimeSpan();
            Connecter1.UpdateTime(time);
            Connecter2.UpdateTime(time);
            AutoLinkObject(new Point(Connecter1.NodeBody.X, Connecter1.NodeBody.Y), new Point(Connecter2.NodeBody.X, Connecter2.NodeBody.Y));

        }
        public void AutoLinkObject(Point position1, Point position2)
        {
            MouseEventArgs EventConnecter1 = new MouseEventArgs(MouseButtons.None, 0, position1.X, position1.Y, 0);
            MouseEventArgs EventConnecter2 = new MouseEventArgs(MouseButtons.None, 0, position2.X, position2.Y, 0);
            SelectObject(null, EventConnecter1);
            UnSelect(null, EventConnecter2);
        }

        #region MouseControl

        void Reset()
        {
            //NodeSelect = null;
            SlastPosition = Vector2.Zero;
            NodeLastPosition = Vector2.Zero;
            LinkSelect = null;
            ConnecterSelect = null;
           //Reset Colors
           // connect.Colors = ReturnColorState(StateNode.NoneSelect, ObjectType.Connecter);
            
        }

        public void UpdateMouseMove(object sender, MouseEventArgs e)
        {      
            if (e.Button == MouseButtons.Left)
            {
                if (NodeSelect != null)
                {
                    if (HoleClick && LinkSelect != null)
                    {
                        NewMove = new Vector2(e.X, e.Y);
                        DictionaryLinkLine[LinkSelect].End = NewMove - camera.MyViewData.Position;
                        //NodeSelect.linkline.End = NewMove-camera.Position;
                    }
                    else
                    {
                        NewMove = new Vector2(e.X, e.Y) - SlastPosition;
                        NodeSelect.MyViewData.Position = NodeLastPosition + NewMove;
                        //Massage3 = this.CloneNodeSelect.MyViewData.Position.ToString();
                    }
                }
                else
                {
                    if (NodeGroupSelect != null)
                    {
                        NewMove = new Vector2(e.X, e.Y) - SlastPosition;
                        NodeGroupSelect.MyViewData.Position = NodeLastPosition + NewMove;
                        NodeGroupSelect.Move();
                    }
                    else if (rectangleselect.NodeSelect.Count != 0 && !rectangleselect.VisiblE)
                    {
                        NewMove = new Vector2(e.X, e.Y) - SlastPosition;
                        rectangleselect.UpdateMove(NewMove);
                    }
                    else
                    {
                        rectangleselect.VisiblE = true;
                        if (rectangleselect.VisiblE)
                        {
                            //Massage3 = 
                            rectangleselect.UpdateSize(SlastPosition, new Vector2(e.X, e.Y));
                            rectangleselect.Selection(MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct]
                                , ReturnColorState(StateNode.Select, ObjectType.Node)
                                , ReturnColorState(StateNode.NoneSelect, ObjectType.Node));
                        }
                    }
                }
            }
        }

        public void SelectObject(object sender, MouseEventArgs e)
        {
            //ArrayList ClonList = (ArrayList)ListObject.Clone();
            NodeSelect = null;
            NodeGroupSelect = null;
            LinkLineSelect = null;
            Reset();
            SlastPosition = new Vector2(e.X, e.Y);

            if(!rectangleselect.DoSelection(new Point(e.X, e.Y),ReturnColorState(StateNode.NoneSelect,ObjectType.Node)))
            {
                #region Collision Node & Connecter
                foreach (String Key in MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct].Keys)
                {
                    NodeObject Node = MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][Key];

                    #region Collision Connecter
                    foreach (Connecter connect in Node.ListConnectpoint)
                    {
                        if (ReturnCollisionClick(connect.NodeBody, e) && LinkSelect == null)
                        {
                            NodeSelect = Node;
                            #region Select connectpoint and Create Line

                            LinkLine temp = new LinkLine(spriteBatch, camera, this.ListDraw, this.DictionaryLinkLine, connect);
                            temp.SetupSourceAndTexture(StoreTexture2D[ImageStore.ImageNodePoint.ToString()]);

                            #region Calcula Name

                            String FindLastKey = "";
                            foreach (String K in DictionaryLinkLine.Keys)
                                FindLastKey = K;
                            temp.MyViewData.Name = ReturnCalculadKeys(ObjectType.Line.ToString(), FindLastKey, DictionaryLinkLine);

                            #endregion

                            temp.AddMetoList();

                            // Save Temp to Check
                            ConnecterSelect = connect;
                            LinkSelect = temp.MyViewData.Name;

                            HoleClick = true;

                            #endregion
                        }
                    }
                    #endregion

                    #region Collision Node
                    if (ReturnCollisionClick(Node.NodeBody, e))
                    {
                        #region Select Node and Initial Drag Node | Else Set NoneSelect
                        if (NodeSelect == null)
                        {
                            NodeSelect = Node;

                            NodeLastPosition = Node.MyViewData.Position;
                            //lastPosition = new Vector2(e.X, e.Y);
                            NewMove = Vector2.Zero;

                            if (!backupaction.Doing)
                                backupaction.TempSave(Node, BackupMode.Position);

                            NodeSelect.MyViewData.Colors = ReturnColorState(StateNode.Select, ObjectType.Node);
                        }
                        //else Node.MyViewData.Colors = ReturnColorState(StateNode.NoneSelect, ObjectType.Node);
                        #endregion
                        //break;
                    }
                    else
                    {

                        Node.MyViewData.Colors = ReturnColorState(StateNode.NoneSelect, ObjectType.Node);
                        foreach (Connecter connect in Node.ListConnectpoint)
                            connect.MyViewData.Colors = ReturnColorState(StateNode.NoneSelect, ObjectType.Connecter);
                        //Reset();
                    }
                    #endregion
                }
                #endregion

                #region Collision Group
                if(NodeSelect == null)
                foreach (String GroupKeys in DictionaryNodeGroup.Keys)
                {
                    if (DictionaryNodeGroup[GroupKeys].ReSize.Intersects(new Rectangle(e.X, e.Y, 1, 1)))
                    {
                        DictionaryNodeGroup[GroupKeys].SetupState();
                        break;
                    }
                    else if (DictionaryNodeGroup[GroupKeys].BodyCancle.Intersects(new Rectangle(e.X, e.Y, 1, 1)))
                    {
                        if (DictionaryNodeGroup[GroupKeys].MyStatE == StateGroup.Minimize)
                            DictionaryNodeGroup[GroupKeys].SetupState();

                        DictionaryNodeGroup[GroupKeys].Remove();
                        break;
                    }
                    else if (DictionaryNodeGroup[GroupKeys].MyStatE == StateGroup.Maximize)
                    {
                        if (DictionaryNodeGroup[GroupKeys].BodymaximizE.Intersects(new Rectangle(e.X, e.Y, 1, 1)))
                        {
                            NodeGroupSelect = DictionaryNodeGroup[GroupKeys];
                            NodeLastPosition = DictionaryNodeGroup[GroupKeys].MyViewData.Position;
                            //lastPosition = new Vector2(e.X, e.Y);
                            NewMove = Vector2.Zero;
                        }
                    }
                    else if (DictionaryNodeGroup[GroupKeys].MyStatE == StateGroup.Minimize)
                    {
                        if (DictionaryNodeGroup[GroupKeys].BodyminimizE.Intersects(new Rectangle(e.X, e.Y, 1, 1)))
                        {
                            NodeGroupSelect = DictionaryNodeGroup[GroupKeys];
                            NodeLastPosition = DictionaryNodeGroup[GroupKeys].MyViewData.Position;
                            //lastPosition = new Vector2(e.X, e.Y);
                            NewMove = Vector2.Zero;
                        }
                    }
                }
                #endregion

                #region Collision LinkLine
                foreach (String K in DictionaryLinkLine.Keys)
                {
                    //DicLinkLine.Keys.Count;
                    //Console.WriteLine("Key = {0}, Value = {1}", DicLinkLine.Key, DicLinkLine.Value);
                    if (DictionaryLinkLine[K].IntersecMouse(new Vector2(e.X, e.Y), 5))
                    {
                        DictionaryLinkLine[K].MyViewData.Colors = ReturnColorState(StateNode.Select, ObjectType.Line);
                        LinkLineSelect = DictionaryLinkLine[K];
                    }
                    else
                        DictionaryLinkLine[K].MyViewData.Colors = ReturnColorState(StateNode.NoneSelect, ObjectType.Line);
                }
                #endregion

                #region Helper Function Check Connecter
                if (NodeSelect != null && ConnecterSelect != null)
                {
                    foreach (String Key in MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct].Keys)
                    {
                        NodeObject Node = MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][Key];

                        if (Node.MyData.MyName != NodeSelect.MyData.MyName)
                        {
                            foreach (Connecter connect in Node.ListConnectpoint)
                            {
                                if (Connectting(ConnecterSelect, connect))
                                    connect.MyViewData.Colors = ReturnColorState(StateNode.Select, ObjectType.Connecter);
                            }
                        }
                    }
                }
                #endregion
            }
        }
        //MouseEventArgs e = new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0);
        public void UnSelect(object sender, MouseEventArgs e)
        {
            if (HoleClick && LinkSelect != null)
            {
                HoleClick = false;
                DictionaryLinkLine[LinkSelect].IsClisk = false;

                //ArrayList ClonList = (ArrayList)ListObject.Clone();
                // Line Connect Complete
                foreach (String Key in MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct].Keys)
                {
                    NodeObject Node = MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][Key];

                    #region Connecting
                    foreach (Connecter connect in Node.ListConnectpoint)
                    {
                        if (ReturnCollisionClick(connect.NodeBody, e))
                        {
                            /// Input to Output || Output to Input Only
                            if (Connectting(ConnecterSelect, connect))
                            {
                                DoAfterConnect(ConnecterSelect, connect);
                                DictionaryLinkLine[LinkSelect].Isconnect = true;

                                if (Start && !backupaction.Doing)
                                {
                                    backupaction.TempSave(DictionaryLinkLine[LinkSelect], BackupMode.CreateLink);
                                    backupaction.BackupMove(BackupMode.CreateLink);
                                }
                                
                            }
                        }
                    }
                    #endregion
                }
            }
            else
            {
                if (NodeSelect != null && Start)
                    if (NodeLastPosition != NodeSelect.MyViewData.Position && !backupaction.Doing && e.Button == MouseButtons.Left)
                        this.backupaction.BackupMove(BackupMode.Position);
            }

            foreach (String Key in MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct].Keys)
            {
                NodeObject Node = MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct][Key];
                foreach (Connecter connect in Node.ListConnectpoint)
                {
                    connect.MyViewData.Colors = ReturnColorState(StateNode.NoneSelect, ObjectType.Connecter);
                }
            }

            rectangleselect.VisiblE = false;
            Reset();
        }

        public void Undo()
        {
            backupaction.Doing = true;
            PackSave getpoint = backupaction.UndoAction(MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct]);
            if (getpoint.inputmode == BackupMode.DeleteNode)
            {
                #region Create LinkLine
                List<Point> TempPoint = new List<Point>();
                for(int i = 1; i< getpoint.inputpacket.Count;i++)
                {
                    if (getpoint.inputpacket[i].GetType() == typeof(Point))
                        TempPoint.Add((Point)getpoint.inputpacket[i]);

                    if (TempPoint.Count == 2)
                    {
                        AutoLinkObject(TempPoint[0], TempPoint[1]);
                        TempPoint.Clear();
                    }
                }
                #endregion
            }
            else if (getpoint.inputmode == BackupMode.DeleteLink)
            {
                CreateLink(getpoint);
            }
            else if (getpoint.inputmode == BackupMode.CreateNode)
            {

            }
            else if (getpoint.inputmode == BackupMode.CreateLink)
            {
                DeleteLink(getpoint);
            }
            backupaction.Doing = false;
        }
        public void Redo()
        {
            backupaction.Doing = true;
            PackSave getpoint = backupaction.RedoAction(MainDictionaryType.GetMaindictionarY[DictionaryType.MainObejct]);
            if (getpoint.inputmode == BackupMode.DeleteLink)
            {
                DeleteLink(getpoint);
            }
            else if (getpoint.inputmode == BackupMode.CreateNode)
            {

            }
            else if (getpoint.inputmode == BackupMode.CreateLink)
            {
                CreateLink(getpoint);
            }
            backupaction.Doing = false;
            
        }
        
        #endregion
        
        void CreateLink(PackSave getpoint)
        {
            Connecter con1 = (Connecter)getpoint.inputpacket[0];
            Connecter con2 = (Connecter)getpoint.inputpacket[1];
            this.FirstConnect(con1, con2);
        }
        void DeleteLink(PackSave getpoint)
        {
            Connecter p = (Connecter)getpoint.inputpacket[0];
            System.TimeSpan time = new TimeSpan();
            p.UpdateTime(time);
            MouseEventArgs EventConnecter1 = new MouseEventArgs(MouseButtons.Left, 0, p.PositionBodyCenter.X, p.PositionBodyCenter.Y, 0);
            SelectObject(null, EventConnecter1);
            DeleteLinkline();
            Reset();
        }
        
        /// <summary>
        /// Update to New Node
        /// </summary>
        public void DoAfterConnect(Connecter connecter_1, Connecter connecter_2)
        {
            Connecter connectInput = null;
            Connecter connectOutput = null;

            if (connecter_1.MySyco == Syco.Input)
            {
                connectInput = connecter_1;
                connectOutput = connecter_2;
            }
            else if (connecter_1.MySyco == Syco.Output)
            {
                connectInput = connecter_2;
                connectOutput = connecter_1;
            }

            /// Check Remove Last Link 
            if (connectInput.MyType != NodeTypeValue.Update && connectInput.MyType != NodeTypeValue.Draw 
                && connectInput.MyNode.MyData.MyType != NodeTypeValue.Gravity)
            {
                //connectInput.MyNode.MyNodeData.MyType
                foreach (LinkLine ThisLink in connectInput.MyNode.LinklinetoConnecter)
                    if (ThisLink.StartConnecter.NodeBody.Intersects(connectInput.NodeBody) ||
                        ThisLink.EndConnecter.NodeBody.Intersects(connectInput.NodeBody))
                    {
                        //ThisLink.MyViewData.Colors = Color.Green;
                        //connecter_1.MyNode.LinklinetoConnecter.Remove(ThisLink);
                        //connecter_2.MyNode.LinklinetoConnecter.Remove(ThisLink);
                        ThisLink.Isconnect = false;
                        break;
                    }
            }
            /// New
            connectInput.MyNode.SetupInput(connectInput,connectOutput);

            #region Backup Think None Use
            //switch (connectInput.MyType)
            //{
            //    case NodeTypeValue.Draw:
            //        connectInput.MyNode.SetupInput(connectOutput);
            //        break;
            //    case NodeTypeValue.Update:
            //        connectInput.MyNode.SetupInput(connectOutput);
            //        break
            //    case NodeTypeValue.Boolean:
            //        break;
            //    case NodeTypeValue.Int:
            //        break;
            //    case NodeTypeValue.Texture2D:
            //        connectInput.MyNode.SetupInput(connectOutput);
            //        //NodeAnimation2D node = (NodeAnimation2D)connect.MyNode;
            //        //Texture2D.FromFile(GraphicsDevice, node.MyData.MyPath);
            //        break;
            //}
            #endregion

            /// Link ConnectEnd Potion
            DictionaryLinkLine[LinkSelect].EndConnecter = connecter_2;
            
            /// Connecter add Link to Node
            connectInput.MyNode.LinklinetoConnecter.Add(DictionaryLinkLine[LinkSelect]);
            connectOutput.MyNode.LinklinetoConnecter.Add(DictionaryLinkLine[LinkSelect]);

            //if(connectInput.MyNode.LinklineInputForSave.Contains(DictionaryLinkLine[LinkSelect]));
            connectInput.MyNode.LinklineInputForSave.Add(DictionaryLinkLine[LinkSelect]);
        }

    }
}
